package com.ciri.ssm.service.impl;

import com.ciri.ssm.dao.BookDao;
import com.ciri.ssm.entity.Book;
import com.ciri.ssm.entity.Users;
import com.ciri.ssm.service.BookService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 图书表(Book)表服务实现类
 *
 * @author makejava
 * @since 2024-05-09 15:10:20
 */
@Service("bookService")
@Transactional
public class BookServiceImpl implements BookService {
    @Resource
    private BookDao bookDao;

    @Override
    public List<Book> selectAll() {
        return bookDao.selectAll();
    }

    /**
     * 通过ID查询单条数据
     *
     * @param bookId 主键
     * @return 实例对象
     */
    @Override
    public Book queryById(Long bookId) {
        return this.bookDao.queryById(bookId);
    }

    /**
     * 分页查询
     *
     * @param book 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
//    @Override
//    public Page<Book> queryByPage(Book book, PageRequest pageRequest) {
//        long total = this.bookDao.count(book);
//        return new PageImpl<>(this.bookDao.queryAllByLimit(book, pageRequest), pageRequest, total);
//    }

    /**
     * 新增数据
     *
     * @param book 实例对象
     * @return 实例对象
     */
    @Override
    public Book insert(Book book) {
        this.bookDao.insert(book);
        return book;
    }

    /**
     * 修改数据
     *
     * @param book 实例对象
     * @return 实例对象
     */
    @Override
    public Book update(Book book) {
        this.bookDao.update(book);
        return this.queryById(book.getBookId());
    }

    /**
     * 通过主键删除数据
     *
     * @param bookId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long bookId) {
        return this.bookDao.deleteById(bookId) > 0;
    }
}
